package designMode.exercise;

/**
 * ũ��һͷСĸţ��
 * ÿ����ͷСĸţ��
 * ĸţ�����ĸţ��
 * ��ʮ���϶���ţ��
 */
import java.util.ArrayList;
import java.util.ListIterator;

public class Cow {
	private int age;

	public Cow(int i) {
		age = i;
	}

	public static void main(String[] args) {
		Farm farm = new Farm();
		farm.getCows().add(new Cow(5));
		for (int i = 0; i < 20; i++) {
			farm.nextYaer();
		}
		System.out.println(farm.getCows().size());
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}
}

class Farm {
	private ArrayList<Cow> cows;

	public Farm() {
		cows = new ArrayList<Cow>();
	}

	public ArrayList<Cow> getCows() {
		return cows;
	}

	public void nextYaer() {
		ListIterator<Cow> lit = cows.listIterator();
		while (lit.hasNext()) {
			Cow cow = lit.next();
			cow.setAge(cow.getAge() + 1);
			if (cow.getAge() >= 5) {
				lit.add(new Cow(1));
			}
		}
	}

	public void setCows(ArrayList<Cow> cows) {
		this.cows = cows;
	}
}
